package com.woniu.controller;

import com.woniu.entity.Result;

import com.woniu.entity.vo.TrainingVO;
import com.woniu.service.ITrainingInfoService;
import com.woniu.service.IUserService;

import com.woniu.service.OrderInfoService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author xiaosong
 * @since 2023-03-31
 */
@RestController
@RequestMapping("/trainingInfo")
@Api(tags = "靶场信息表")
public class TrainingInfoController extends BaseController{

    @Autowired
    private ITrainingInfoService trainingInfoService;

    @Autowired
    private OrderInfoService orderInfoService;

    @Autowired
    private IUserService userService;



    @ApiOperation("靶场信息展示")
    @GetMapping("/information/{trainingId}")
    public Result selectInformation(@PathVariable Integer trainingId){
//     通过id,查询展示信息封装到vo中，展示到前端页面
        TrainingVO trainingVo =  trainingInfoService.selectInformation(trainingId);

          return toDataResult(trainingVo);
    }
//  查询用户是否购买过此靶场。
    @ApiOperation("查询是否购买过该靶场")
    @GetMapping("/pay/{userId}/{trainingId}")
    public Result selectPurchase(@PathVariable Integer userId,@PathVariable Integer trainingId){
       boolean flag =   orderInfoService.selectOrder(userId,trainingId);
       return toDataResult(flag);
    }
//  查询该用户是不是vip,
    @ApiOperation("查询用户是不是vip")
    @GetMapping("/vip/{userId}")
    public Result selectVip(@PathVariable Integer userId){
        boolean flag = userService.selectVip(userId);
        return toDataResult(flag);
    }


}
